﻿using System;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace ShopSpace.SchemaGenerator
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("********************************");
			Console.WriteLine("ShopSpace Schema Generator Tool");
			Console.WriteLine("********************************");
			Console.WriteLine("");
			Console.WriteLine("Hit [Enter] to continue");
			Console.WriteLine("");
			Console.ReadLine();
			try
			{
				string outputFile = System.Configuration.ConfigurationManager.AppSettings["OutputFile"];
				bool showOutput = Boolean.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowOutput"]);
				Console.WriteLine("Loading Configuration...");
				Configuration config = new Configuration();
				config.Configure();
				config.BuildSessionFactory();
				SchemaExport schemaExport = new SchemaExport(config);
				schemaExport.SetOutputFile(outputFile);
				Console.WriteLine("Exporting Schema to {0}", outputFile);
				schemaExport.Create(showOutput, false);
				Console.WriteLine("Operation completed successfully");
				Console.ReadLine();
			}
			catch ( Exception ex )
			{
				Console.WriteLine("Error : {0}", ex.Message);
				Console.ReadLine();
				Console.WriteLine(ex.ToString());
				Console.ReadLine();
			}
		}
	}
}